package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysCexpense;
import com.ruoyi.project.system.service.SysCexpeService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author :sxt
 * @dote :21:38 2021/7/16
 */
@RestController
@RequestMapping("/system/cexpense")
public class SysCexpeController  extends BaseController {

    @Autowired
    private SysCexpeService sysCexpeService;

    /**
     * 分页查询List
     * @param sysCexpense  模糊查询
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:cexpense:query')")
    @GetMapping("/getList")
    public TableDataInfo getList(SysCexpense sysCexpense){
        //分页相关
        startPage();
        List<SysCexpense>list=sysCexpeService.getList(sysCexpense);
        return getDataTable(list);
    }

    /**
     * 查询所有检查项目费用，要项目类别
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:cexpense:query')")
    @GetMapping("/getCexpenseSort")
    public AjaxResult getCexpenseSort(){
       List<SysCexpense> list=sysCexpeService.getCexpenseSort();
        return AjaxResult.success(list);
    }


    /**
     * 根据指定ID查询检查项目费用信息
     * @param scId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:cexpense:query')")
    @GetMapping("/getCeById/{scId}")
    public AjaxResult getCeById(@PathVariable Integer scId){
        SysCexpense sysCexpense=sysCexpeService.getCeById(scId);
        return AjaxResult.success(sysCexpense);
    }

    /**
     * 增加检查项目信息
     * @param sysCexpense
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:cexpense:add')")
    @PostMapping("/add")
    public AjaxResult addCexpense(@RequestBody SysCexpense sysCexpense){
        sysCexpense.setCreateBy(SecurityUtils.getUsername());
        sysCexpense.setCreateTime(new Date());
        int row=sysCexpeService.addCexpense(sysCexpense);
        return toAjax(row);
    }

    /**
     * 修改检查项目信息
     * @param sysCexpense
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:cexpense:edit')")
    @PutMapping("/update")
    public AjaxResult updateCexpense(@RequestBody SysCexpense sysCexpense){
        sysCexpense.setUpdateBy(SecurityUtils.getUsername());
        sysCexpense.setUpdateTime(new Date());
        int row=sysCexpeService.updateCexpense(sysCexpense);
        return toAjax(row);
    }


    /**
     * 删除检查费用信息
     * @param scIds  是要删除的记录的id，是个数组，支持批量删除
     * @return
     */
    @Transactional
    @PreAuthorize("@ss.hasPermi('system:cexpense:remove')")
    @DeleteMapping("/remove/{scIds}")
    public AjaxResult delCexpense(@PathVariable Integer [] scIds){
        int row=sysCexpeService.removeCexpense(scIds);
        return toAjax(row);
    }





}
